package com.tomas.demo.controller;

import com.tomas.demo.entity.Demo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  测试 中文乱码解决方案
 *  //responseBody中文乱码 因为默认的相应编码"ISO-8859-1"
 *  converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
 */
@Slf4j
@Controller
@RequestMapping(value = "/test")
public class TestEncondingController {

    //http://localhost:8080/test/show?name=你好这是中文
    @ResponseBody
    @RequestMapping(value = "/show", method= RequestMethod.GET)// 这里指定RequestMethod，如果不指定Swagger会把所有RequestMethod都输出，在实际应用中，具体指定请求类型也使接口更为严谨。
    @ApiOperation(value="测试接口", notes="测试接口详细描述")
    public String message_cn(@ApiParam(required=true, name="name", value="姓名")
                       @RequestParam(name = "name") String name){
       log.info("demo name is {}",name);
        return "name="+name;
    }

    //http://localhost:8080/test/message_cn?name=你好这是中文&content=中文
    @ResponseBody
    @RequestMapping(value = "/message_cn", method= RequestMethod.GET)
    public Demo message_cn(Demo demo){
        return demo;
    }

}